﻿DROP TRIGGER IF EXISTS  `pk_color_lib_log`;
CREATE  TRIGGER `pk_color_lib_log` AFTER INSERT ON `open_color_lib`
  FOR EACH ROW BEGIN
 dECLARE pkf varchar(50) DEFAULT "";
 sELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="color_lib";
 if pkf <> "color_lib" then
   INSERT INTO open_pk_log SET pk_from = 'color_lib', pk_id = NEW.img_id;
 eLSE
    update open_pk_log SET pk_id = NEW.img_id WHERE pk_from = 'color_lib';
 end if;
 end;